/**2013-4-10
 zhangqj
 * 
 */
package com.data;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * Java connect Oracle
 * ip:172.16.1.140
 * @author zhangqj
 *2013-4-10
 */
public class DBConnection {
	private final static String URL="jdbc:oracle:thin:@172.16.1.140:1521:orcl";
	private final static String Driver="oracle.jdbc.driver.OracleDriver";
	private final static String User="tnms";
	private final static String Pwd="tnms";
	Connection conn=null;
	/*
	 * connect the database
	 */
	public Connection getConnection(){
	
		try {
			Class.forName(Driver);
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		try {
			conn=DriverManager.getConnection(URL,User,Pwd);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return conn;
	}
	/*
	 * close the connection
	 */
	public void closeConnection(Connection conn){
		if(conn!=null){
			try {
				if(!conn.isClosed()){
					try {
						conn.close();
					} catch (SQLException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	

}
